﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Utils;
using POS.Framework;
using Model.Bill;
using BLL;
using BLL.Enums;

namespace POS.ModForm.Bill
{
    public partial class frmOrderForm : DevExpress.XtraEditors.XtraForm
    {
        TB_Order order = null;
        public frmOrderForm()
        {
            InitializeComponent();
        }

        private void frmOrderForm_Load(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm(MsgBox.WaitLoading))
            {
                this.gridView.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(SpecialGridView.DrawRowIndicator);
                this.repositoryItemLookUpEditProductType.DataSource = EnumManage.GetDictionaryEntry(typeof(ProductType));
                this.repositoryItemLookUpEditUnit.DataSource = EnumManage.GetDictionaryEntry(BaseEnum.Unit);
                this.SetButtonClickEvent();
                this.GetModule();
                wdf.Close();
            }
        }
        void SetButtonClickEvent()
        {
            this.formButtonUC.Hide();
            //this.formButtonUC.IsHide(new List<string> { "btnSave","btnCostSet" });
            //this.formButtonUC.Examine.Click += Examine_Click;
        }
        void GetModule()
        {
            if (this.Tag != null && !string.IsNullOrEmpty(this.Tag.ToString()))
            {
                order = DatabaseSchema.Session.GetObjectByKey<TB_Order>(this.Tag.ToString());
                this.gridControl.DataSource = order.OrderDetails;
                ShowOrderUI();
            }
        }
        void ShowOrderUI()
        {
            if (order != null)
            {
                this.groupControl.Text = string.Format("销售单号：{0}  状态：{1}", order.BillCode, EnumManage.GetBillStatus(typeof(OrderStatus), order.StatusID));
                this._StoreName.Text = order.StoreID.StoreName;
                this._SellDate.Text = order.SellDate.ToString("yyyy-MM-dd");
                this._CopeAmount.Text = order.CopeAmount.ToString("f2");
                this._ActualAmount.Text = order.ActualAmount.ToString("f2");
            }
        }
    }
}